<?php

class MakeNewPostView {
	
	const NEW_POST = "newpost";
	
	//Form for update post
	public function GetForm($a_categoryArray){
		return "<h1>Ny post</h1>
		<form method='post' name='updatePost' action='' enctype = 'multipart/form-data' >
			<h2>Ange rubrik</h2><input type='text' name='".ObserverView::POST_HEADER."' text =''/><br />
			<textarea name='".ObserverView::POST_CONTENT."' id='content' class='mceEditor' rows='25' cols='100' tabindex='2'></textarea>
			<input type='hidden' name= '".ObserverView::POST_URLPARAMETER."' id=''/>
			<input type='submit' name='".self::NEW_POST."' value='Uppdatera'/>
			".$this->PopulateDropdown($a_categoryArray)."
		</form>";
	}
	
	//Returns a category dropdown menu Xhtml
	public function PopulateDropdown ($a_categoryArray){
		$ret ="";
		$ret.= "<select name='".ObserverView::CATEGORYID."'>";
			foreach($a_categoryArray as $category){
				$ret .= "<option value='".$category[ObserverView::CATEGORYID]."''.>".$category[ObserverView::CATEGORYNAME]."</option>";
			}
			$ret .= "</select>";
		
		return $ret;
	}
	
	//Chekcs if the user has tried to upload post
	public function TriedToUploadPost (){
		if(isset($_POST[self::NEW_POST])){
			return true;
		}else{
			return false;
		}
	}
	
	//Get the content from the new post and puts it in an associative array
	public function GetNewPostContents(){
		$ret = array();
		$ret[ObserverView::POST_HEADER] = $_POST[ObserverView::POST_HEADER];
		$ret[ObserverView::POST_CONTENT] = $_POST[ObserverView::POST_CONTENT];
		$ret[ObserverView::CATEGORYID] = $_POST[ObserverView::CATEGORYID];
		
		return $ret;
	}
}